/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:lenovo
 * Date:2024-05-12
 * Time:20:09
 */
class Student {
    public String name;
    public int num;
    public double score;
    public static String className = "方法一";
    //静态变量的初始化
    //1.就地初始化 2.get set方法 3.构造方法（不建议） 4.静态代码块

    static {
        className = "方法四";
        System.out.println("静态代码块方法...");
    }

    {
        //实例代码块
        System.out.println("实例代码块方法...");
    }

    //构造方法会在实例化的时候调用
    public Student() {
        //那假设构造函数可以被static修饰，那是不是意味我们想要在没有对象的前提下调用构造函数，进而初始化成员变量？
        // 对象都没有，怎么能初始化成员变量呢？
        /*this.name = name;
        this.num = num;
        this.score = score;*/
        className = "方法三";
        System.out.println("构造方法...");
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", num=" + num +
                ", score=" + score +
                '}';
    }
}



public class Test {
    public static void main(String[] args) {
        Student student1 = new Student();
        /*Student.setClassName("方法二");
        Student.getClassName();*/
        System.out.println(Student.className);
        System.out.println(student1);
    }
}

